package com.windgo.controller.wx;

import com.github.pagehelper.PageInfo;
import com.windgo.bean.MarketUser;
import com.windgo.bean.common.BaseRespVo;
import com.windgo.bean.common.CommonData;
import com.windgo.bean.vo.WxFootprintListVO;
import com.windgo.bean.vo.WxIssueVO;
import com.windgo.service.WxIssueService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("wx/issue")
public class WxIssueController {
    @Autowired
    WxIssueService wxIssueService;

    @RequestMapping("list")
    public BaseRespVo<CommonData<WxIssueVO>> issueList(Integer page,Integer limit){
//        Subject subject = SecurityUtils.getSubject();
//        PrincipalCollection principals = subject.getPrincipals();
//        MarketUser primaryPrincipal = (MarketUser) principals.getPrimaryPrincipal();
//        Integer userId = primaryPrincipal.getId();
//        Integer userId = 1;
        CommonData<WxIssueVO> commonData = new CommonData<>();
        PageInfo<WxIssueVO> pageInfo = wxIssueService.listWxIssue(page,limit);
        int total = Long.valueOf(pageInfo.getTotal()).intValue();
        int pages = pageInfo.getPages();
        int pageNum = pageInfo.getPageNum();
        List<WxIssueVO> list = pageInfo.getList();
        commonData.setTotal(total);
        commonData.setPages(pages);
        commonData.setLimit(limit);
        commonData.setPage(pageNum);
        commonData.setList(list);
        return BaseRespVo.ok(commonData);
    }
}
